#include"serialize/fragment.h"

//fragment definition
Fragment::Fragment()
{
    id = 0;
    name = "";
    description = "";
}

Fragment::Fragment(qint32 _id, QString _name, QString _description)
{
    id = _id;
    name = _name;
    description = _description;
}

Fragment::Fragment(const Fragment& f)
{
    id = f.id;
    name = f.name;
    description = f.description;
}

Fragment& Fragment::operator=(const Fragment& f)
{
    if(&f == this)
        return *this;

    id = f.id;
    name = f.name;
    description = f.description;

    return *this;
}

Fragment::~Fragment()
{
}

ostream& operator <<(ostream& os,Fragment& f)
{
    os<<"******start******"<<endl;
    os<<"Fragment info:"<<endl;
    os<<"id:"<<(int)f.id<<endl;
    os<<"name:"<<f.name.toStdString()<<endl;
    os<<"description:"<<f.description.toStdString()<<endl;
    os<<"******end******"<<endl;

    return os;
}

QDataStream& operator<<(QDataStream& ds,Fragment& f)
{
    ds<<f.id;
    ds<<f.name.toUtf8().data();
    ds<<f.description.toUtf8().data();

    return ds;
}

QDataStream& operator>>(QDataStream& ds,Fragment& f)
{
    ds>>f.id;
    char* temp;
    ds>>temp;
    f.name = QString::fromUtf8(temp);
    delete[] temp;
    ds>>temp;
    f.description = QString::fromUtf8(temp);
    delete[] temp;

    return ds;
}


